package cn.xiuxius.embedded.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.experimental.Accessors;

@Accessors(chain = true)
public class IntegerFlashOptionType extends AbstractFlashOptionType<Integer> {


    public IntegerFlashOptionType(String name, Integer value, String cmdValue, boolean isDefault) {
        super(value, cmdValue, isDefault);
    }

    public IntegerFlashOptionType() {
    }

    public static final IntegerFlashOptionType DEFAULT = new IntegerFlashOptionType("default", 0, "default", true);

    @JsonCreator
    public static IntegerFlashOptionType from(Object val) {
        if (val instanceof Integer) {
            return new IntegerFlashOptionType("default", (Integer) val, "default", false);
        }
        if (val instanceof String s) {
            if ("DEFAULT".equalsIgnoreCase(s)) {
                return DEFAULT;
            }
        }
        throw new IllegalArgumentException("Unsupported NumType input: " + val);
    }

    @Override
    public String getCmdValue() {
        return String.valueOf(getValue());
    }


    @Override
    public boolean isDefault() {
        return DEFAULT.equals(this);
    }


}
